on Command
Invoked when a command is received by a component this listener is registered with.
Implementers should typically use a switch statement or if-else-if chain on the name} parameter to identify the command and then process it accordingly, using the arg} parameter if provided.
The specific set of command names and the expected format or meaning of their arguments are defined by the system or component issuing the commands. Refer to the relevant documentation for available commands and their usage.
Example command handling:
*public void onCommand(String name, String arg) {
if ("RESTART_PLAYER".equalsIgnoreCase(name)) {
// Code to restart the player
} else if ("SET_VOLUME".equalsIgnoreCase(name)) {
try {
int volumeLevel = Integer.parseInt(arg);
// Code to set player volume
} catch (NumberFormatException e) {
// Log error: invalid volume argument
}
} else if ("NAVIGATE_TO".equalsIgnoreCase(name)) {
// Code to navigate to a screen or URL specified in 'arg'
} else {
// Log: unhandled command
}
}
This method constructs a JavaScript command to be executed in the WebView. The command calls the `RevelDigital.Controller.onCommand` function with the provided `name` and `value` as arguments. It also escapes single quotes in the name and value to prevent JavaScript injection issues.
Additionally, it attempts to create a JSON object containing the command name and argument, and triggers a JavaScript event named "RevelDigital.Command" with this JSON object as its data.
Parameters
The name of the command.
The value or argument associated with the command.